﻿using SiteUtils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using VINETLIFE;
using VINETLIFE.BL;
using VINETLIFE.DO;

namespace VINETLIFE
{
    public partial class BusinessPartner : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int partnerTypeId = 0;
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                partnerTypeId = int.Parse(Request.QueryString["ID"]);
            }
            else
            {
            }
            if (!IsPostBack)
            {
                SEO();
                LoadData(partnerTypeId);
            }
        }
        protected void SEO()
        {
            sysConfigDO objConfig = new sysConfigDO();
            objConfig.ConfigID = 2;

            objConfig = new sysConfigBL().Select(objConfig);

            Page.Title = "Business Partner | " + Ultility.WebTitle();

            HtmlMeta metaKey = new HtmlMeta();
            metaKey.Name = "keywords";
            metaKey.Content = objConfig.ConfigValue;
            Page.Header.Controls.Add(metaKey);

            objConfig.ConfigID = 3;
            objConfig = new sysConfigBL().Select(objConfig);
            HtmlMeta metaDesc = new HtmlMeta();
            metaDesc.Name = "description";
            metaDesc.Content = objConfig.ConfigValue;
            Page.Header.Controls.Add(metaDesc);
        }
        protected void LoadData(int partnerTypeId)
        {
            rptPartnerType.DataSource = new cmsPartnerTypeBL().SelectByCondition(0, 0, partnerTypeId);
            rptPartnerType.DataBind();
        }
        protected void LoadPartner(DataTable dt, CollectionPager collect, int pagesize, Repeater rpt)
        {
            string sortBy = "";
            if (dt.Rows.Count > 0)
            {
                collect.MaxPages = 10000;
                collect.PageSize = pagesize; // số items hiển thị trên một trang
                collect.DataSource = new DataView(dt, "", sortBy, DataViewRowState.CurrentRows);
                collect.BindToControl = rpt;
                rpt.DataSource = collect.DataSourcePaged;
                rpt.DataBind();
            }
            else { }
        }
        protected void rptPartnerType_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                DataRowView drv = (DataRowView)e.Item.DataItem;
                Label lblPartnerDetail = (Label)e.Item.FindControl("lblPartnerDetail");
                CollectionPager collectPartner = (CollectionPager)e.Item.FindControl("collectPartner");
                Repeater rptPartner = (Repeater)e.Item.FindControl("rptPartner");

                int partnerTypeId = int.Parse(drv["PartnerTypeId"].ToString());
                if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
                {
                    lblPartnerDetail.Visible = false;
                    collectPartner.Visible = true;

                    LoadPartner(new cmsDoiTacBL().SelectByTypeAndTop(0, partnerTypeId), collectPartner, 24, rptPartner);
                }
                else
                {
                    lblPartnerDetail.Visible = true;
                    collectPartner.Visible = false;

                    rptPartner.DataSource = new cmsDoiTacBL().SelectByTypeAndTop(6, partnerTypeId);
                    rptPartner.DataBind();
                }
            }
        }
        public string FriendlyUrl(string s)
        {
            return Ultility.Change_AV(s);
        }
    }
}